﻿using ConfExpert.Forms.Base;
using DevTeam;

using System;

namespace ConfExpert.Forms.Depo
{
    public partial class Liste1P : XForm
    {
        public Liste1P()
        {
            InitializeComponent();
        }

        private void Liste1P_Load(object sender, EventArgs e)
        {
            
            gvRoll.Init("GetGP3", 0, 0);
            gvRoll.AddSummary("Qty");
            gvRoll.Columns["OwnerId"].Caption = "Mal Sahibi";
            gvRoll.Columns["VendorId"].Caption = "Üretici";
            //gvRoll.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;

            btnKaydet.ItemClick += btnKaydet_ItemClick;
           // gvRoll.OptionsBehavior.Editable =  ytk(126);
            btnKaydet.Visibility = ytk(126) ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never;
            sleArt.Edit.Assign(RI(Rp.V_Kumas));
          //  sleArt.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Default;
            sleArt.EditValueChanged += new EventHandler(sleArt_EditValueChanged);

            gvRoll.ShowingEditor += new System.ComponentModel.CancelEventHandler(gvRoll_ShowingEditor);
            txtRoll.EditValueChanged += new EventHandler(txtRoll_EditValueChanged);
            gvRoll.BestFitColumns();
           // gvRoll.Columns["KontrolMetraji"].Width =60;
            foreach(string col in new string[] {
                "IplikKacigi",
                "KanatFarki",
                "BoyaKirigi",
                "Leke",
                "EnineBant",
                "DesenHatasi",
                "YabanciElyaf",
                "NepsKumasBiti",
                "Delik",
                "Abraj",
                "Diger",
                "HataSayisi"})
            gvRoll.Columns[col].Width = 70;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvRoll.EndEditing();
            string xml = gvRoll.SerializeChanges();
            gvRoll.Update("RollId,KaliteKontrolId,Kalite2,OwnerId,LotNr", "Roll");
           // ExecuteNonQuery("UpdateHoldForReset");
            ExecuteNonQuery("SetKaliteKontrol", xml);
            gvRoll.RefreshDataSource("GetGP3", intParse(sleArt.EditValue), intParse(txtRoll.EditValue));
            gvRoll.BestFitColumns();
        }

        void gvRoll_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = (gvRoll.FocusedColumn.FieldName != "KaliteKontrolId" &&
                gvRoll.FocusedColumn.FieldName != "Kalite2" &&
                gvRoll.FocusedColumn.FieldName != "OwnerId" &&
                gvRoll.FocusedColumn.FieldName != "KontrolMetraji" &&
                gvRoll.FocusedColumn.FieldName != "IplikKacigi" &&
                gvRoll.FocusedColumn.FieldName != "KanatFarki" &&
                gvRoll.FocusedColumn.FieldName != "BoyaKirigi" &&
                gvRoll.FocusedColumn.FieldName != "Leke" &&
                gvRoll.FocusedColumn.FieldName != "EnineBant" &&
                gvRoll.FocusedColumn.FieldName != "DesenHatasi" &&
                gvRoll.FocusedColumn.FieldName != "YabanciElyaf" &&
                gvRoll.FocusedColumn.FieldName != "NepsKumasBiti" &&
                 gvRoll.FocusedColumn.FieldName != "Delik" &&
                  gvRoll.FocusedColumn.FieldName != "Abraj" &&
                   gvRoll.FocusedColumn.FieldName != "Diger" &&
                           gvRoll.FocusedColumn.FieldName != "En" &&
                gvRoll.FocusedColumn.FieldName != "LotNr");
        }


        void txtRoll_EditValueChanged(object sender, EventArgs e)
        {
            if (intParse(txtRoll.EditValue) > 0)
            {
                sleArt.EditValue = null;
                gvRoll.RefreshDataSource("GetGP3", intParse(sleArt.EditValue), intParse(txtRoll.EditValue));
                gvRoll.BestFitColumns();

                gvRoll.FocusedRowHandle = gvRoll.LocateByValue("RollId", intParse(txtRoll.EditValue));
                gvRoll.MakeRowVisible(gvRoll.FocusedRowHandle);
            }
        }

        void sleArt_EditValueChanged(object sender, EventArgs e)
        {
            if (intParse(sleArt.EditValue) > 0)
            {
                txtRoll.EditValue = null;
                gvRoll.RefreshDataSource("GetGP3", intParse(sleArt.EditValue), intParse(txtRoll.EditValue));
                gvRoll.BestFitColumns();
            }
        }

        /*
        void HataGir(object sender, EventArgs e)
        {
            int RollId = intParse(gvRoll.GetRowCellValue(gvRoll.FocusedRowHandle, "RollId"));
            int KaliteKontrolId = intParse(gvRoll.GetRowCellValue(gvRoll.FocusedRowHandle, "KaliteKontrolId"));
            KumasHata kh = new KumasHata(RollId, KaliteKontrolId);
            DialogResult dr = kh.ShowDialog();

            if (dr == DialogResult.OK)
            {
                if (kh.KaliteKontrolId > 0)
                    gvRoll.SetRowCellValue(gvRoll.FocusedRowHandle, "KaliteKontrolId", kh.KaliteKontrolId);
                else
                    gvRoll.SetRowCellValue(gvRoll.FocusedRowHandle, "KaliteKontrolId", DBNull.Value);

            }
        }
         */
    }
}